package org.corey.share.business;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.corey.share.db.entity.CoreyFile;
import org.corey.share.db.service.CoreyFileService;
import org.corey.share.db.service.CoreyFileServiceImpl;

import com.google.appengine.api.datastore.Blob;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class CoreyFileShowAction extends ActionSupport{
	private CoreyFileService service = new CoreyFileServiceImpl();
	private String url;
	private Long id;
	private CoreyFile file;

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public InputStream getCoreyFile() {
		if(id!=null){
			this.file=service.getFile(id);
		}else{
			this.file = service.getFile(url);
		}
		Blob content = file.getContent();
		byte[] buf = content.getBytes();
		return new ByteArrayInputStream(buf);
	}

	public String execute() {
		return SUCCESS;
	}

}
